package server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.ResultSetMetaData;


public class TestMySql {
	public static void main(String[] args)
    {
		String[][] t = new String[4][2];
		t[0][0] = "first_name";
		t[0][1] = "Teststststst";
		t[1][0] = "last_name";
		t[1][1] = "safdlkjdslkjasd";
		
		MySQLConnection mysql = new MySQLConnection();
        //mysql.add("actor", "first_name", "Halllllllllo");
        //mysql.add("actor", t);
        //mysql.getName("actor","first_name");
        //if(mysql.add("actor", t)) System.out.println("Delete");
		//mysql.getName("Objects", "ID");
		mysql.add("Objects", new String[][]{	{"name",			"Hallo"										},
					{"translation.x",	"2"		},
					{"translation.y",	"2"		},
					{"translation.z",	"2"		},
					{"rotation.x",		"2"		},
					{"rotation.y",		"2"		},
					{"rotation.z",		"2"		},
					{"rotation.w",		"2"		},
					{"scale.x",			"2"		},
					{"scale.y",			"2"		},
					{"scale.z",			"2"		}});
		try {
			//System.out.println(mysql.getResult("SELECT * FROM `worldofgothic`.`objects` WHERE `objects`.`ID` = '"+4+"'").getString("ID"));
			//ResultSet result = mysql.getResult("SELECT * FROM `worldofgothic`.`objects` WHERE `objects`.`ID` = '"+4+"'");
			//result.last();
			//System.out.println(result);
			//getColumnNames(result);
			String bufferSQL = "";
			ResultSet result = mysql.getResult("SELECT * FROM `objects`");
       	 while(result.next()) {
       		 for(int i=1;i<=result.getMetaData().getColumnCount();i++) {
       			 //if(i!=0) bufferSQL = bufferSQL + "~";
       			 bufferSQL = bufferSQL + "~" + result.getString(i);
       		 }
       		System.out.println(bufferSQL);
       		bufferSQL = "";
      		 
       	 }
		} catch (SQLException e) {
			System.out.println(e);
		}
	}
	public static void getColumnNames(ResultSet rs) throws SQLException {
	    if (rs == null) {
	      return;
	    }
	    ResultSetMetaData rsMetaData = rs.getMetaData();
	    int numberOfColumns = rsMetaData.getColumnCount();
	    
	    // get the column names; column indexes start from 1
	    for (int i = 1; i < numberOfColumns + 1; i++) {
	      String columnName = rsMetaData.getColumnName(i);
	      // Get the name of the column's table name
	      String tableName = rsMetaData.getTableName(i);
	      System.out.println("column name=" + columnName + " table=" + tableName + "");
	    }
	  }
}
